﻿using ArtClub.Model;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace ArtClub.DAL
{
    internal class ArtClubContext : DbContext
    {
        public ArtClubContext()
            : base("Data Source=(LocalDb)\\v11.0;Initial Catalog=ArtClub1;Integrated Security=SSPI;")
        {
            //shouldn't be here (maybe)
            Database.Initialize(true);
        }

        public DbSet<Member> Members { get; set; }

        public DbSet<Bid> Bids { get; set; }

        public DbSet<Auction> Auctions { get; set; }

        public DbSet<Art> Arts { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Don't use pluralizing table names.
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            // Set database initialization.
            Database.SetInitializer<ArtClubContext>(new ArtClubInitializer());


			// Auction.AuctionItem not null.
			modelBuilder.Entity<Auction>().HasRequired(p => p.AuctionItem);

			// Bid.Bidder not null.
			modelBuilder.Entity<Bid>().HasRequired(p => p.Bidder);
        }
    }
}